package cn.maihe.elg.operation.supports.bank.ccb.ebs.dto;

import cn.maihe.elg.operation.supports.bank.ccb.ebs.exception.CCBPayApiException;
import cn.maihe.elg.operation.supports.bank.ccb.ebs.util.XmlUtils;
import cn.maihe.elg.operation.utils.DateUtil;
import cn.maihe.elg.operation.utils.StringUtil;
import lombok.Data;
import org.w3c.dom.Element;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * （6WY105）汇总账户某日逐笔明细查询
 *
 * @author Alan
 * @version 1.0  2024/11/2
 */
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="TX_INFO")
public class CCBEbsTransDetailQueryReq extends CCBEbsBaseReq {

    private static final long serialVersionUID = -3164148818956457153L;
    /**
     * 账号
     */
    @XmlElement(name="ACCNO1")
    private String accNo;
    /**
     * 交易日期 YYYYMMDD
     */
    @XmlElement(name="TRANDATE")
    private String tranDate;
    /**
     * 对方账户 可选
     */
    @XmlElement(name="CHECK_ACC_NO")
    private String checkAccNo;
    /**
     * 对方账户名称 可选
     */
    @XmlElement(name="CHECK_ACC_NAME")
    private String checkAccName;
    /**
     * 备注 可选
     */
    @XmlElement(name="REMARK")
    private String remark;
    /**
     * 起始页 可选 查询页次，整数>0
     */
    @XmlElement(name="PAGE")
    private int page;
    /**
     * 定位串 可选 第一次查询为空
     */
    @XmlElement(name="POSTSTR")
    private String postStr;
    /**
     * 每页记录数 可选 默认为10，大于0小于等于200，后续查询时的输入值，必须与首次查询设定的值相等
     */
    @XmlElement(name="TOTAL_RECORD")
    private int totalRecord;
    /**
     * 交易流水号 int 可选
     */
    @XmlElement(name="TRAN_FLOW")
    private String tranFlow;
    /**
     * 起始明细编号 int 可选 此明细号用于快速查询某条记录以后的明细数据(可参考返回报文DET_NO填写此值)
     */
    @XmlElement(name="DET_NO")
    private String detNo;
    /**
     * 交易方向 可选 空是全部 1转出 2转入
     */
    @XmlElement(name="DBTCRDRCCD")
    private String dbTcrDrCcd;

    /**
     * 汇总账户某日逐笔明细查询 txCode：6WY105
     *
     * @author Alan  v1.0   2024/11/2
     */
    public CCBEbsTransDetailQueryReq(String custId, String userId, String passWord, String txCode, String accNo, String tranDate) {
        super(custId, userId, passWord, txCode);

        this.accNo = accNo;
        this.tranDate = StringUtil.isBlank(tranDate) ? DateUtil.getCurrentDate() : tranDate;
        this.checkAccNo = "";
        this.checkAccName = "";
        this.remark = "";
        this.page = 1;
        this.postStr = "";
        this.totalRecord = 50;
        this.tranFlow = "";
        this.detNo = "";
        this.dbTcrDrCcd = "";
    }

    public String toReqXML() throws CCBPayApiException {
        Element tx = XmlUtils.createRootElement("TX");
        XmlUtils.appendElement(tx, "REQUEST_SN").setTextContent(this.getRequestSn() == null ? "" : this.getRequestSn());
        XmlUtils.appendElement(tx, "CUST_ID").setTextContent(this.getCustId() == null ? "" : this.getCustId());
        XmlUtils.appendElement(tx, "USER_ID").setTextContent(this.getUserId() == null ? "" : this.getUserId());
        XmlUtils.appendElement(tx, "PASSWORD").setTextContent(this.getPassword() == null ? "" : this.getPassword());
        XmlUtils.appendElement(tx, "TX_CODE").setTextContent(this.getTxCode() == null ? "" : this.getTxCode());
        XmlUtils.appendElement(tx, "LANGUAGE").setTextContent(this.getLanguage() == null ? "" : getLanguage());
        Element txInfo = XmlUtils.appendElement(tx, "TX_INFO");
        XmlUtils.appendElement(txInfo, "ACCNO1").setTextContent(this.accNo == null ? "" : this.accNo);
        XmlUtils.appendElement(txInfo, "TRANDATE").setTextContent(this.tranDate == null ? "" : this.tranDate);
        XmlUtils.appendElement(txInfo, "CHECK_ACC_NO").setTextContent(this.checkAccNo == null ? "" : this.checkAccNo);
        XmlUtils.appendElement(txInfo, "CHECK_ACC_NAME").setTextContent(this.checkAccName == null ? "" : this.checkAccName);
        XmlUtils.appendElement(txInfo, "REMARK").setTextContent(this.remark == null ? "" : this.remark);
        XmlUtils.appendElement(txInfo, "PAGE").setTextContent(String.valueOf(this.page));
        XmlUtils.appendElement(txInfo, "POSTSTR").setTextContent(this.postStr == null ? "" : this.postStr);
        XmlUtils.appendElement(txInfo, "TOTAL_RECORD").setTextContent(String.valueOf(this.totalRecord));
        XmlUtils.appendElement(txInfo, "TRAN_FLOW").setTextContent(this.tranFlow == null ? "" : this.tranFlow);
        XmlUtils.appendElement(txInfo, "DET_NO").setTextContent(this.detNo == null ? "" : this.detNo);
        XmlUtils.appendElement(txInfo, "DBTCRDRCCD").setTextContent(this.dbTcrDrCcd == null ? "" : this.dbTcrDrCcd);
        return XmlUtils.nodeToString(tx);
    }
}
